//
//  WeatherView.m
//  KYProject
//
//  Created by Roman on 16/12/20.
//  Copyright © 2016年 Roman. All rights reserved.
//

#import "WeatherView.h"
#import "WeatherModel.h"


@interface WeatherView()

//天气图片
@property (weak, nonatomic) IBOutlet UIImageView *iv_weather;

//天气
@property (weak, nonatomic) IBOutlet UILabel *lb_weather;

//日期
@property (weak, nonatomic) IBOutlet UILabel *lb_data;

//温度
@property (weak, nonatomic) IBOutlet UILabel *lb_temperature;

@end

@implementation WeatherView

+ (instancetype)weatherview
{
    
    return [[NSBundle mainBundle] loadNibNamed:@"WeatherView" owner:nil options:nil].lastObject;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    
}

#pragma mark
#pragma mark - 切换地点

- (void)setupLocationWithCity:(NSString *)cityName
{
    //获取文字内容:
    NSMutableAttributedString *string = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@",cityName]];
    
    //设置下划线范围
    NSRange contentRange = {0, [string length]};
    
    //加下划线
    [string addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:contentRange];
    
    _bt_location.titleLabel.attributedText = string;
}

- (IBAction)clickButton{
    //字体变蓝色
    [_bt_location setTitleColor:[UIColor blueColor] forState:UIControlStateHighlighted];
    
    //通知 把点击事件传递给主登录界面
    [[NSNotificationCenter defaultCenter] postNotificationName:@"clickHomeView" object:nil];
    
}




//获取网络数据;
- (void)getWeatherDataWithCity:(NSString *)cityName
{
    
    WeatherModel *model = [[WeatherModel alloc] init];
    
    [model getWeatherWithCityName:cityName complete:^(WeatherModel *model, NSError *error) {
        
        //日期
        NSArray *dateArr = [model.date componentsSeparatedByString:@" "];
        
        _lb_data.text = [NSString stringWithFormat:@"%@ %@", dateArr[0], dateArr[1]];
        
        _lb_weather.text = model.weather;
        
        _lb_temperature.text = model.temperature;
        
        [_iv_weather sd_setImageWithURL:[NSURL URLWithString:model.nightPictureUrl]];
    }];
    
}

@end
